<template>
  <el-steps
    class="status-steps-mobile sa-m-t-32"
    direction="vertical"
    :active="state.orderStep"
    :align-center="true"
    :space="80"
  >
    <el-step title="买家下单">
      <template #description>
        <div>{{ props.orderDetail.create_time }}</div>
        <div class="step-status">待付款</div>
      </template>
    </el-step>
    <el-step
      :title="props.orderDetail.status == 'pending' && props.orderDetail.pay_mode=='offline'?'货到付款':'买家付款'">
      <template #description>
          <div>{{ props.orderDetail.status == 'pending' &&
              props.orderDetail.pay_mode=='offline'?props.orderDetail.ext?.pending_date:props.orderDetail.paid_time
              }}</div>
          <div class="step-status">待发货</div>
      </template>
    </el-step>
    <el-step title="商家发货">
      <template #description>
        <div>{{ props.orderDetail?.ext?.send_date }}</div>
        <div class="step-status">待收货</div>
      </template>
    </el-step>
    <el-step title="买家收货">
      <template #description>
        <div>{{ props.orderDetail?.ext?.confirm_date }}</div>
        <div class="step-status">待评价</div>
      </template>
    </el-step>
    <el-step title="完成交易" :description="props.orderDetail?.ext?.completed_date"></el-step>
  </el-steps>
  <el-steps
    class="status-steps-pc sa-m-t-32"
    direction="horizontal"
    :active="state.orderStep"
    :align-center="true"
  >
    <el-step title="买家下单">
      <template #description>
        <div>{{ props.orderDetail.create_time }}</div>
        <div class="step-status">待付款</div>
      </template>
    </el-step>
    <el-step
      :title="props.orderDetail.status == 'pending' && props.orderDetail.pay_mode=='offline'?'货到付款':'买家付款'">
      <template #description>
          <div>{{ props.orderDetail.status == 'pending' &&
              props.orderDetail.pay_mode=='offline'?props.orderDetail.ext?.pending_date:props.orderDetail.paid_time
              }}</div>
          <div class="step-status">待发货</div>
      </template>
    </el-step>
    <el-step title="商家发货">
      <template #description>
        <div>{{ props.orderDetail?.ext?.send_date }}</div>
        <div class="step-status">待收货</div>
      </template>
    </el-step>
    <el-step title="买家收货">
      <template #description>
        <div>{{ props.orderDetail?.ext?.confirm_date }}</div>
        <div class="step-status">待评价</div>
      </template>
    </el-step>
    <el-step title="完成交易" :description="props.orderDetail?.ext?.completed_date"></el-step>
  </el-steps>
</template>
<script setup>
  import { reactive, watch } from 'vue';

  const props = defineProps(['orderDetail']);

  const state = reactive({
    orderStep: 1,
  });

  function changeOrderStep() {
    if (props.orderDetail.status == 'unpaid') {
      state.orderStep = 1;
    } else if (props.orderDetail.status == 'paid' || (props.orderDetail.status == 'pending' && props.orderDetail.pay_mode == 'offline')) {
      state.orderStep = 2;
      switch (props.orderDetail.status_code) {
        case 'nosend':
          state.orderStep = 2;
          break;
        case 'noget':
          state.orderStep = 3;
          break;
        case 'nocomment':
          state.orderStep = 4;
          break;
        case 'commented':
          state.orderStep = 4;
          break;
      }
    } else if (props.orderDetail.status == 'completed') {
      state.orderStep = 5;
    }
  }
  watch(
    () => props.orderDetail,
    () => {
      changeOrderStep();
    },
  );
</script>
<style lang="scss" scoped>
  .status-steps-mobile,
  .status-steps-pc {
    :deep() {
      .el-step__head {
        .el-step__line {
          top: 15px;
        }
        .el-step__icon {
          width: 32px;
          height: 32px;
          color: var(--sa-background-assist);
          background: var(--sa-place);
          border: 2px solid var(--sa-table-header-bg);
        }
        &.is-finish {
          .el-step__icon {
            color: var(--sa-background-assist);
            background: var(--el-color-primary);
          }
        }
      }
      .el-step__title {
        color: var(--sa-subfont);
        font-size: 14px;
        font-weight: 400;
        &.is-finish {
          color: var(--sa-subtitle);
        }
      }
      .el-step__description {
        padding: 0;
        color: var(--sa-subfont);
        &.is-finish {
          .step-status {
            color: var(--el-color-primary);
          }
        }
      }
    }

    .step-status {
      color: var(--sa-font);
      font-size: 14px;
    }
  }
  .status-steps-mobile {
    display: none;
    @media only screen and (max-width: 768px) {
      display: flex;
    }
    :deep() {
      .el-step__head {
        width: fit-content;
        .el-step__line {
          left: 15px;
        }
      }
    }
  }
  .status-steps-pc {
    display: flex;
    @media only screen and (max-width: 768px) {
      display: none;
    }
    .step-status {
      position: absolute;
      top: -12px;
      right: -30px;
      width: 60px;
    }
  }
</style>
